package per.wsj.okhttp

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import per.wsj.commonlib.utils.LogUtil
import java.lang.reflect.Type
import java.util.*

object TestUtils {

    inline fun <reified T> request(url: String) {
        val type = object : TypeToken<T>() {}.type
        LogUtil.e(type.toString())
    }

    inline fun <reified T> request0(url: String) {
        val gson = Gson()
        val result = gson.fromJson<List<String>>(getJsonStr(), T::class.java)
        LogUtil.e(result.toString())
    }

    fun getJsonStr(): String {
        val listType: Type = object : TypeToken<List<String>>() {}.type
        val target: MutableList<String> = LinkedList()
        target.add("blah")

        val gson = Gson()
        val json: String = gson.toJson(target, listType)
        return json
    }

    inline fun <T> request2(url: String) {
        val type = object : TypeToken<T>() {}.type
        LogUtil.e(type.toString())
    }
}